﻿/**
 * 异步提交表单
 * @param {UI Element}   form     表单元素
 * @param {Function} callback 异步提交的回调函数
 */
define(['jquery'], function ($) {

    var _utils = {};

    _utils.formSubmit = function (form, callback, complete) {
        $.ajax({
            url: form.action,
            type: form.method,
            data: $(form).serialize(),
            beforeSend: function () {

            },
            success: function (result) {
                callback(result);
            },
            complete: function () {
                if (complete) {
                    complete();
                }
            },
            error: function (result) {
                //alert("提交表单失败：" + result);
            }
        });
    };

    _utils.waittingButton = function (sender) {
        if (sender) {
            var _sender = $(sender);
            if (_sender.attr('_value')) {
                _sender.attr('value', _sender.attr('_value'));
                _sender.removeAttr('_value');
            } else {
                _sender.attr('_value', _sender.attr('value'));
                _sender.attr('value', _sender.attr('value') + '...');
            }
        }
    };

    _utils.waittingLink = function (sender) {
        if (sender) {
            var _sender = $(sender);
            if (_sender.attr('_text')) {
                _sender.text(_sender.attr('_text'));
                _sender.removeAttr('_text');
            } else {
                _sender.attr('_text', _sender.text());
                _sender.text(_sender.text() + '...');
            }
        }
    };
    

    return _utils;
});
